﻿using System;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Interop;
using System.Windows.Media.Animation;

namespace AgLux
{
    public enum Filling { full = 100, threeFourth = 75, half = 50, oneFourth = 25 }

    /// <summary>
    /// Represents a page that displays an intro and then a Course object.
    /// </summary>

    public partial class Page : Canvas
    {
        /// <summary>
        /// Occurs when the page is loaded.
        /// </summary>

        /// <param name="sender">
        /// The object that raised the event.
        /// </param>

        /// <param name="args">
        /// The EventArgs that contains the event data.
        /// </param>

        public void Page_Loaded(object sender, EventArgs args)
        {
            InitializeComponent();

            second.Begin();
            second.Completed += new EventHandler(StartIntro);
        }

        /// <summary>
        /// Occurs when it is time to start the intro.
        /// </summary>

        /// <param name="sender">
        /// The object that raised the event.
        /// </param>

        /// <param name="args">
        /// The EventArgs that contains the event data.
        /// </param>

        private void StartIntro(object sender, EventArgs args)
        {
            Width = introArea.Width = BrowserHost.ActualWidth;
            Height = introArea.Height = BrowserHost.ActualHeight;

            agluxLogotype.SetValue(Canvas.LeftProperty, Width / 2 - agluxLogotype.Width / 2);
            agluxLogotype.SetValue(Canvas.TopProperty, Height / 2 - agluxLogotype.Height / 2 - 25);

            agluxElearning.SetValue(Canvas.LeftProperty, Width / 2 - agluxElearning.Width / 2);
            agluxElearning.SetValue(Canvas.TopProperty, Height / 2 - agluxElearning.Height / 2);

            developed.SetValue(Canvas.LeftProperty, Width / 2 - developed.ActualWidth / 2);
            developed.SetValue(Canvas.TopProperty, Height / 2 - developed.ActualHeight / 2);

            silverlightLogotype.SetValue(Canvas.LeftProperty, Width / 2 - silverlightLogotype.Width / 2);
            silverlightLogotype.SetValue(Canvas.TopProperty, Height / 2 - (silverlightLogotype.Height + microsoft.Height + silverlight.Height + 30) / 2);

            microsoft.SetValue(Canvas.LeftProperty, Width);
            microsoft.SetValue(Canvas.TopProperty, Height / 2 - (silverlightLogotype.Height + microsoft.Height + silverlight.Height + 30) / 2 + silverlightLogotype.Height + 10);

            silverlight.SetValue(Canvas.LeftProperty, -silverlight.Width);
            silverlight.SetValue(Canvas.TopProperty, Height / 2 - (silverlightLogotype.Height + microsoft.Height + silverlight.Height + 30) / 2 + silverlightLogotype.Height + microsoft.Height + 20);

            by.SetValue(Canvas.LeftProperty, Width / 2 - by.Width / 2);
            by.SetValue(Canvas.TopProperty, Height / 2 - by.Height / 2);

            microsoftDistance.Value = -Width / 2 - silverlight.Width / 2;
            silverlightDistance.Value = Width / 2 + silverlight.Width / 2;

            intro.Begin();
            agluxSignature.Play();

            intro.Completed += new EventHandler(EndIntro);
            introArea.MouseLeftButtonDown += new MouseEventHandler(EndIntro);
        }

        /// <summary>
        /// Occurs when it is time to end the intro.
        /// </summary>

        /// <param name="sender">
        /// The object that raised the event.
        /// </param>

        /// <param name="args">
        /// The EventArgs that contains the event data.
        /// </param>

        private void EndIntro(object sender, EventArgs args)
        {
            Resources.Clear();
            Children.Clear();
            Children.Add(Parser.ParseCourse());
        }
    }
}
